<?php

namespace app\model;

use think\Model;

class AgeOdds extends Model
{
    // 获取年龄概率
    public function all()
    {
        return $this->select();
    }

    // 增加概率
    public function add($max, $min, $odds)
    {
        $this->save([
            'max' => $max,
            'min' => $min,
            'odds' => $odds,
        ]); 
    }

    // 修改概率
    public function upd($data)
    {
        $info = $this->find($data['id']);
        if (!empty($info)) {
            $save = [];

            foreach ($data as $key => $val) {
                if (!empty($val)) {
                    $save[$key] = $val;
                }
            }

            $info->save($save);
        }
    }

    // 删除
    public function del($id)
    {
        $this->destroy($id);
    }
}
